package com.jinrustar.httpfileserver.springboot.controller;

import com.jinrustar.httpfileserver.core.HttpFileServerApp;
import com.jinrustar.httpfileserver.core.base.BaseController;
import com.jinrustar.httpfileserver.core.http.HttpFileServer;
import com.jinrustar.httpfileserver.core.util.WebUtil;
import com.jinrustar.httpfileserver.util.FileUtil;
import io.swagger.annotations.Api;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.FileInputStream;
import java.io.IOException;

/**
 * @Api(value = "玩客云", description = "玩客云")
 */
@Controller
        /*@Api(value = "玩客云", description = "玩客云")*/
@RequestMapping(value = "/wankecloud", method = {RequestMethod.GET, RequestMethod.POST})
public class WankeCloudController extends BaseController {

    private static final Logger logger = LoggerFactory.getLogger(WankeCloudController.class);

    @RequestMapping(value = "/qrcode")
    public void qrcode(ModelMap modelMap, HttpServletRequest request, HttpServletResponse response, HttpSession httpSession
    ) throws IOException {
        logger.info("###ip:{}", WebUtil.getHost(request));
        /*response.addHeader("Content-Type", "image/jpeg");
        response.getOutputStream().write(FileUtil.read(new FileInputStream(HttpFileServerApp.QR_IMG_PATH)));*/
        response.sendRedirect(HttpFileServer.ipAndPort + "?path=/qrcode");
    }

    @RequestMapping(value = "/show")
    public ModelAndView show(ModelMap modelMap, HttpServletRequest request, HttpServletResponse response, HttpSession httpSession) {
        logger.info("###ip:{}", WebUtil.getHost(request));
        return new ModelAndView("index");
    }

    @RequestMapping(value = "/upload")
    public String upload() {
        return "upload";
    }

}
